
(function(){
	var isImage = false, imageUrl = "";
	
	document.addEventListener("dragend", function(event){
		if(isImage){
			if(imageUrl.indexOf("googleusercontent.com/") >= 0){
				imageUrl = imageUrl.replace(/\/(s\d+|w\d+\-h\d+)\//i, "/s0/");
			}
			chrome.extension.sendRequest({"type": "viewImage", "url": imageUrl});
		}
		isImage = false;
	}, false);
	
	document.addEventListener("mousedown", function(event){
		var obj = event.target;
		isImage = false;
		if(obj.tagName == "IMG"){
			isImage = true;
			imageUrl = obj.src;
		}
	}, false);
	
	document.addEventListener("mouseup", function(event){
		isImage = false;
	}, false);

})();